<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户注册</title>
</head>
<body>
<div id="app">
    <h1>注册用户</h1>
    昵称：<input type="text" v-model="nickname" placeholder="请输入昵称">
    <br><br>
    用户名：<input type="text" v-model="username" placeholder="请输入用户名">
    <br>
    <br>
   密码：<input type="password" v-model="password" placeholder="请输入密码">
    <br>
    <div v-if="message" style="color: red">{{message}}</div>
    <br>
    <button @click="registerUser()">注册</button>
    <br>
    <br>
    <button @click="login()">点我跳转至登录页面</button>
</div>


<script type="application/javascript" src="../js/vue.js"></script>
<script type="application/javascript" src="../js/axios.js"></script>

<script>
    let app = new Vue({
        el:"#app",
        data:{
            nickname:'',
            username:'',
            password:'',
            message:''
        },
        methods:{
            registerUser:function () {
                app.message='';
                axios.post("../register",{
                    nickname: app.nickname,
                    username: app.username,
                    password: app.password
                }).then(function (resp) {
                    let body = resp.data;
                    if (body.success){
                        alert("注册成功，自动为你跳转至登录页面")
                        window.location.href="login.html";
                    }else {
                        app.message=body.message
                    }
                })
            },
            login:function () {
                window.location.href="login.html";
            }
        }
    })
</script>
</body>
</html>